<template>
  <div>
    loginName:<input type="text" ref="login" /><br>
    password:<input type="text" ref="admin" /><br>
    code:<input type="text" ref="refCode" v-model="loginForm.code"/>
    <img :src="`http://likede2-admin.itheima.net/likede/api/user-service/user/imageCode/${loginForm.clientToken}`" alt="" @click="changeImg"><br>
    <button @click="loginFn">LOGIN</button>
  </div>
</template>

<script>
// import { loginAPI } from '@/api'
export default {
  name: 'Login',
  data () {
    return {
      loginForm: {
        loginName: 'admin',
        password: 'admin',
        code: '',
        clientToken: Math.random(),
        loginType: 0
      }
    }
  },
  methods: {
    // 修改验证码图片
    changeImg () {
      this.loginForm.clientToken = Math.random()
      console.log(this.loginForm.clientToken)
    },

    // 点击登录
    async loginFn () {
      const res = await this.$store.dispatch('asyncLoginAction', this.loginForm)
      console.log(res.msg)
      alert(res.msg)
      if (res.success) this.$router.push('/home')
    }
  }

}
</script>

<style>
</style>
